<template>
  <el-row :gutter="20">
    <el-col :span="10" offset="7">
      <el-card v-if="!showSuccess" class="box-card">
        <el-form
          ref="form"
          :model="form"
          label-position="top"
          style="margin-top: 5vh"
          label-width="80px"
        >
          <el-form-item label="请输入密码">
            <el-input v-model="form.pass" placeholder="请输入重置密码"/>
          </el-form-item>
          <el-form-item label="请再次输入密码">
            <el-input v-model="form.passagain" placeholder="请再次输入重置密码"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">重置密码</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card v-if="showSuccess" class="box-card">
        <div
          style="display: flex;flex-direction: column;align-items: center;justify-content: center"
        >
          <img src="../../assets/完成.png" style="width: 150px;height: 150px;margin-bottom: 2vh">
          <span style="margin-bottom: 2vh">重置成功</span>
          <router-link to="/login">
            <el-button type="success">现在去登录</el-button>
          </router-link>
        </div>
      </el-card>
    </el-col>
  </el-row>
</template>

<script>
import { fetchList } from '@/api/api'

export default {
  name: '', data() {
    return {
      form: { pass: '', passagain: '' }, showSuccess: false
    }
  }, methods: {
    onSubmit() {
      if (!this.form.pass) {
        this.$message.error('请输入登录邮箱！')
        return
      }

      if (this.form.pass !== this.form.passagain) {
        this.$message.error('两次输入的密码不相符！')
        return
      }

      const param = this.form
      param.query = 'vue_供货商重置密码'
      param.code = this.$route.query.code
      param.email = this.$route.query.email

      fetchList(param).then(({ data }) => {
        if (data.flag === '0') {
          this.$message.error(data.message)
          return
        }
        this.showSuccess = true
      })
    }
  }
}
</script>

<style scoped>
.box-card {
  height: 50vh;
  min-height: 400px;
  margin-top: 10vh;
  padding: 5vh;
}
</style>
